﻿// Copyright (c) Vitaly Kamiansky. All rights reserved. 
// See License.txt in the project root.

using Property.Reloaders;
using Property.Timers;
using System;

namespace Property.Windows
{
    /// <summary>
    /// Contains words that extend the description 
    /// of a property's reload process.
    /// </summary>
    public static class ReloaderPrototypeExtensionsCallbacksWindows
    {
        /// <summary>
        /// <para>... if not overruled by another call in the specified period of time (when) ...</para>
        /// <para>( ! ) Don't forget to dispose of what you create with this word.</para>
        /// </summary>
        /// <param name="dueTime">Tell me how much time I should wait for another 
        /// call before letting this one pass.</param>
        /// <param name="testMode">Tell me if I have to ignore this word.</param>
        public static IReloaderPrototype<T> Delayed<T>(this IReloaderPrototype<T> source, TimeSpan dueTime, bool testMode = false)
        {
            if (source == null) throw new ArgumentNullException("source");

            return testMode ? source :
                new ThrottleReloaderDecoratorPrototype<T>(source, new DispatcherTimerPrototype(dueTime));
        }
    }
}
